package com.zzyl.controller;


import com.github.pagehelper.Page;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing")
@Api(tags = "护理计划")
public class NursingPlanController extends BaseController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @ApiOperation(value = "查询所有护理计划列表")
    @GetMapping("/plan")
    public ResponseResult<List<NursingPlanVo>> getAll() {
        List<NursingPlanVo> nursingPlanVoList = nursingPlanService.getAll();
        return success(nursingPlanVoList);
    }

    @ApiOperation(value = "新增")
    @PostMapping("/plan")
    public ResponseResult add(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.add(nursingPlanDto);
        return success();
    }

    @ApiOperation(value = "查询")
    @GetMapping("/plan/search")
    public ResponseResult<PageResponse<NursingPlanVo>> getPage(
            @ApiParam(value = "姓名") String name,
            @ApiParam(value = "状态") Integer status,
            @ApiParam(value = "每页显示数量", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "当前页码", defaultValue = "10") Integer pageSize
    ) {
        PageResponse<NursingPlanVo> pageResponse = nursingPlanService.getPage(name, status, pageNum, pageSize);
        return success(pageResponse);
    }

    @ApiOperation(value = "修改回显/根据ID查询")
    @GetMapping("/plan/{id}")
    public ResponseResult<NursingPlanVo> getById(@PathVariable Integer id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return success(nursingPlanVo);
    }

    @ApiOperation(value = "修改")
    @PutMapping("/plan/{id}")
    public ResponseResult update(@RequestBody NursingPlanDto nursingPlanDto, @PathVariable Long id) {
        System.out.println(id);
        nursingPlanService.update(nursingPlanDto, id);
        return success();
    }

    @ApiOperation(value = "修改状态")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        nursingPlanService.updateStatus(id, status);
        return success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/plan/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        nursingPlanService.delete(id);
        return success();
    }
}
